package com.example.demo02.dao;


import com.example.demo02.entity.Goods;

import java.util.HashMap;
import java.util.Map;

public class GoodsDao {

    private static Map<Integer, Goods> goodsMap = new HashMap<Integer, Goods>();

    static {
        goodsMap.put(1, new Goods(1,"机器学习导论",99));
        goodsMap.put(2,new Goods(2,"数据结构与算法", 43));
    }

    public static Map<Integer, Goods> findAllGoods() {
        return goodsMap;
    }

    public static Goods findGoodsById(int id) {
        return goodsMap.get(id);
    }

    public static void addGoods(Goods goods) {
        goodsMap.put(goods.getId(), goods);
    }

    public static void deleteGoods(int id) {
        goodsMap.remove(id);
    }

    public static void updateGoods(Goods goods) {
        goodsMap.put(goods.getId(), goods);
    }

}
